//
//  PhotoChooseController.m
//  Arts1
//
//  Created by apple on 15/9/16.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "PhotoChooseController.h"

#import "AllHeader.h"

@interface PhotoChooseController ()

@end

@implementation PhotoChooseController

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.rowHeight = 50;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *title = @"添加";
    
    return title;
}

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    myView.backgroundColor = kCustomColor(245, 245, 245, 1);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 90, 22)];
    titleLabel.textColor=kCustomColor(150, 150, 150, 1);
    titleLabel.text = @"添加";
    titleLabel.font = [UIFont systemFontOfSize:14];
    [myView addSubview:titleLabel];
    return myView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    if (indexPath.row == 0)
    {
        cell.imageView.image = [UIImage imageNamed:@"photoAlbumIcon"];
        cell.imageView.frame = CGRectMake(18, 10*HEIGHT, 28, 28*HEIGHT);
        cell.textLabel.text = @"从相册选择";
        cell.textLabel.textColor = kCustomColor(40, 40, 50, 1);
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        
        UIView *lineView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0.1, cell.size.width, 0.5)];
        lineView1.backgroundColor = kCustomColor(150, 150, 150, 0.5);
        [cell.contentView addSubview:lineView1];
    }
    else
    {
        cell.imageView.image = [UIImage imageNamed:@"captureIcon"];
        cell.textLabel.text = @"拍照";
        cell.textLabel.textColor = kCustomColor(40, 40, 50, 1);
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(18, 0.5, cell.size.width - 18, 0.5)];
        lineView.backgroundColor = kCustomColor(150, 150, 150, 0.5);
        [cell.contentView addSubview:lineView];
    }
    
    // Configure the cell...
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0)//从相册选择
    {
        NSLog(@"从相册选择");
        if (_choosephotoblock) {
            _choosephotoblock(0);
        }
        
    }
    else//拍照
    {
        NSLog(@"拍照");
        if (_choosephotoblock) {
            _choosephotoblock(1);
        }
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
